<template>



    <!-- 运营人信息显示 -->
    <el-card style="width:400px;margin:0 auto">
        <p class="p">
            租户信息
        </p>

        <el-form ref="ruleFormRef" :model="operator" :rules="addRules" label-width="100px" :inline="false"
            style="width:400px;">
            <el-form-item label="商户名称：" prop="TenantId">
                <el-input v-model="operator.TenantId"></el-input>
            </el-form-item>
            <el-form-item label="登录账号：" prop="UName">
                <el-input v-model="operator.UName"></el-input>
            </el-form-item>
            <el-form-item label="登录密码：" prop="UPwd">
                <el-input v-model="operator.UPwd"></el-input>
            </el-form-item>
            <el-form-item label="姓名：" prop="Name">
                <el-input v-model="operator.Name"></el-input>
            </el-form-item>
            <el-form-item label="手机号：" prop="Tel">
                <el-input v-model="operator.Tel"></el-input>
            </el-form-item>
            <el-form-item label="QQ号：" prop="QQ">
                <el-input v-model="operator.QQ"></el-input>
            </el-form-item>
            <el-form-item label="微信号：" prop="WeChar">
                <el-input v-model="operator.WeChar"></el-input>
            </el-form-item>
            <el-form-item label="邮箱：" prop="Emails">
                <el-input v-model="operator.Emails"></el-input>
            </el-form-item>
            <el-form-item label="是否分库：" size="normal">
                <el-radio-group v-model="operator.isSplitDB">
                    <el-radio :label="true">是</el-radio>
                    <el-radio :label="false">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item size="normal">
                <el-button type="success" @click="tenantAdd">保存</el-button>
                <el-button type="default" @click="router.back()">返回</el-button>
            </el-form-item>

        </el-form>
    </el-card>


</template>



<script setup lang="ts">
import { ElForm, ElMessage } from "element-plus"
import { reactive, ref, onMounted } from "vue"
import router from '@/router';
import type { FormInstance, FormRules } from 'element-plus'

import axios from 'axios';
import { baseURL_dev } from '@/config/baseURL'

const baseURL = baseURL_dev
axios.defaults.baseURL = baseURL;


const operator = reactive({
    TenantId: "cfy",
    UName: "cfy",
    UPwd: "123",
    Name: "靓仔",
    Tel: "13142390366",
    QQ: "465016011",
    WeChar: "13142390366",
    Emails: "465016011@qq.com",
    isSplitDB: false,
});
const ruleFormRef = ref<FormInstance>()
/* interface ListMenu {
    PId: number,
    PName: string,
    ParentId: string,
    Path: string,
    Icon: string,
    Children: ListMenu[]
} */
const addRules = reactive<FormRules<typeof operator>>({
    TenantId: [
        { required: true, message: '请输入商户名称', trigger: 'blur' },],
    UName: [
        { required: true, message: '请输入登录账号', trigger: 'blur' },],
    UPwd: [
        { required: true, message: '请输入登录密码', trigger: 'blur' },
    ],
    Name: [
        { required: true, message: '请输入姓名', trigger: 'blur' },
    ],
    Tel: [
        { required: true, message: '请输入手机号', trigger: 'blur' },
        {
            pattern: /^1[3-9]\d{9}$/,
            message: '手机号格式不正确',
            trigger: 'blur'
        }],
    QQ: [
        { required: true, message: '请输入QQ号', trigger: 'blur' },
        {
            pattern: /^\d+$/,
            message: 'QQ号格式不正确',
            trigger: 'blur'
        }
    ],
    WeChar: [
        { required: true, message: '请输入微信号', trigger: 'blur' },
    ],
    Emails: [
        { required: true, message: '请输入邮箱', trigger: 'blur' },
        {
            pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
            message: '邮箱格式不正确',
            trigger: 'blur'
        }
    ]

})
//租户信息添加
function tenantAdd() {
    axios.post("Tenant/TenantAdd", operator).then(res => {
        if (res.data.Code == 200) {
            ElMessage({
                message: '注册成功',
                type: 'success',
            })
            router.push("/applyStore")
        } else {
            ElMessage({
                message: res.data.Msg,
                type: 'error',
            })

        }
    })
}






onMounted(() => {


})
</script>

<style scoped>
.p {
    font-weight: bold;
    margin-bottom: 20px;
    text-align: center
}

.el-form-item {
    width: 350px;
}
</style>